package cn.niit.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
//动态代理
public class MyIncovationHandler implements InvocationHandler {

private Object target;

    public MyIncovationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        return null;
    }
    public Object getProxy(){
        return Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),

                new InvocationHandler(){

                    @Override
                    public Object invoke(Object Proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("即将调用"+method.getName());
                        System.out.println(method.getName()+"User");
                       Object returnVal= method.invoke(target,args);
//                        System.out.println(target.getClass());
                        System.out.println(method.getName()+"执行已完成");
                        return returnVal;
                    }
                }
        );


    }

}
